import Ember from 'ember';

export default Ember.Route.extend({
  valueShareer: Ember.inject.service("value-shareer"),
  model(params) {
    var tree = this.get('valueShareer').get('tree');
    if (params.nid === "-1") {
      this.transitionTo(this.get('routeName'), tree, tree.get('treeJson').root);
      return;
    } else {
      return tree.get('__indexer')[params.nid];
    }
  },
  serialize(model) {
    return {
      nid: model.get('id')
    };
  },
  actions: {
    toChildren(tn) {
      var controller = this.get('controller');
      this.transitionTo(this.get('routeName'), controller.get('treeModel'), tn);
    }
  }
});
